﻿using LaoLuo;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace LaoLuo.Common.Test
{
    
    
    /// <summary>
    ///这是 DateTimeHelperTest 的测试类，旨在
    ///包含所有 DateTimeHelperTest 单元测试
    ///</summary>
    [TestClass()]
    public class DateTimeHelperTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///ChangeDate 的测试
        ///</summary>
        [TestMethod()]
        public void ChangeDateTest()
        {
            var date = new DateTime(2001, 12, 12, 12, 59, 59);
            Assert.AreEqual(new DateTime(2001, 12, 12, 12, 33, 33), new DateTime(2000, 1, 1, 12, 33, 33).ChangeDate(date));
            Assert.AreEqual(new DateTime(2010, 1, 9, 12, 33, 33), new DateTime(2000, 2, 1, 12, 33, 33).ChangeDate(9, 1, 2010));
            Assert.AreEqual(new DateTime(2000, 1, 9, 12, 33, 33), new DateTime(2000, 2, 1, 12, 33, 33).ChangeDate(9, 1));
            Assert.AreEqual(new DateTime(2000, 2, 9, 12, 33, 33), new DateTime(2000, 2, 1, 12, 33, 33).ChangeDate(9));
            Assert.AreEqual(new DateTime(2000, 2, 1, 12, 33, 33), new DateTime(2000, 2, 1, 12, 33, 33).ChangeDate(null));
            Assert.AreEqual(new DateTime(2009, 12, 1, 12, 33, 33), new DateTime(2000, 2, 1, 12, 33, 33).ChangeYearAndMonth(new DateTime(2009, 12, 1)));
            
        }


        /// <summary>
        ///ChangeTime 的测试
        ///</summary>
        [TestMethod()]
        public void ChangeTimeTest()
        {
            var time = new DateTime(2001, 12, 12, 11, 59, 59);
            Assert.AreEqual(new DateTime(2000, 1, 1, 11, 59, 59), new DateTime(2000, 1, 1, 12, 33, 33).ChangeTime(time));
            Assert.AreEqual(new DateTime(2000, 1, 1, 1, 1, 1), new DateTime(2000, 1, 1, 12, 33, 33).ChangeTime(1, 1, 1));
            Assert.AreEqual(new DateTime(2000, 1, 1, 11, 11, 59), new DateTime(2000, 1, 1, 12, 33, 33).ChangeTime("11:11:59"));
            try
            {
                new DateTime(2000, 1, 1, 12, 33, 33).ChangeTime("11:11:59d");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
            }
        }

        /// <summary>
        ///IsSameDateWith 的测试
        ///</summary>
        [TestMethod()]
        public void IsSameDateWithTest()
        {
            Assert.AreEqual(true, new DateTime(2001, 12, 12, 11, 59, 59).IsSameDateWith(new DateTime(2001, 12, 12, 1, 1, 1)));
            Assert.AreNotEqual(true, new DateTime(2001, 12, 12, 11, 59, 59).IsSameDateWith(new DateTime(2010, 12, 12, 1, 1, 1)));
            Assert.AreNotEqual(true, new DateTime(2001, 12, 12, 11, 59, 59).IsSameDateWith(new DateTime(2001, 11, 12, 1, 1, 1)));
            Assert.AreNotEqual(true, new DateTime(2001, 12, 12, 11, 59, 59).IsSameDateWith(new DateTime(2001, 12, 11, 1, 1, 1)));
        }

        /// <summary>
        ///IsWeekend 的测试
        ///</summary>
        [TestMethod()]
        public void IsWeekendTest()
        {
            Assert.IsTrue(new DateTime(2012, 1, 7).IsWeekend());
            Assert.IsTrue(new DateTime(2012, 1, 8).IsWeekend());
            Assert.IsFalse(new DateTime(2012, 1, 9).IsWeekend());
            Assert.IsFalse(new DateTime(2012, 1, 6).IsWeekend());
        }

        /// <summary>
        ///GetDescription 的测试
        ///</summary>
        [TestMethod()]
        public void GetDescriptionTest()
        {
            Assert.AreEqual(1 + " minutes ago", DateTime.Now.AddSeconds(-60).GetDescription());
            Assert.AreEqual(" just now", DateTime.Now.AddSeconds(-5).GetDescription());
            Assert.AreEqual(3 + " hours ago", DateTime.Now.AddHours(-3).GetDescription());
            Assert.AreEqual("2011-11-11", new DateTime(2011, 11, 11).GetDescription());
        }

        /// <summary>
        ///ToChinese 的测试
        ///</summary>
        [TestMethod()]
        public void ToChineseTest()
        {
            var prefix = "周";
            Assert.AreEqual(prefix + "日", DayOfWeek.Sunday.ToChinese(prefix));
            Assert.AreEqual(prefix + "一", DayOfWeek.Monday.ToChinese(prefix));
            Assert.AreEqual(prefix + "二", DayOfWeek.Tuesday.ToChinese(prefix));
            Assert.AreEqual(prefix + "三", DayOfWeek.Wednesday.ToChinese(prefix));
            Assert.AreEqual(prefix + "四", DayOfWeek.Thursday.ToChinese(prefix));
            Assert.AreEqual(prefix + "五", DayOfWeek.Friday.ToChinese(prefix));
            Assert.AreEqual(prefix + "六", DayOfWeek.Saturday.ToChinese(prefix));
        }

        /// <summary>
        ///GetMonthInterval 的测试
        ///</summary>
        [TestMethod()]
        public void GetMonthIntervalTest()
        {
            Assert.AreEqual(
                Interval<DateTime>.NewClosedInterval(new DateTime(2012, 7, 1), new DateTime(2012, 7, 31)),
                new DateTime(2012, 7, 11).GetMonthInterval()
                );

            Assert.AreEqual(
                Interval<DateTime>.NewClosedInterval(new DateTime(2012, 6, 1), new DateTime(2012, 6, 30)),
                new DateTime(2012, 6, 11).GetMonthInterval()
                );
        }
    }
}
